#! /bin/sh
FUGEN=./fugen
BONG=./bong

if [ ! -f cairo.interface ] ; then
cat <<EOT >cairo.interface
|
| cairographics.org binding to HelFORTH
|
lazylink libcairo.so
::     " cairo" >pad over >r +
       swap 0 ?do
         over c@ dup 'a u<if 32 or
           swap '_ over c! 1+ swap
         then over c! 1+ swap 1+ swap
       loop nip r> tuck -
; is word>sym
context Cairo
{~ Cairo
EOT

rename='
  $funa =~ s/^cairo_(.)/uc($1)/e;
  $funa =~ s/_(.)/uc($1)/ge;
'
for a in cairo.h cairo-pdf.h cairo-ps.h cairo-svg.h \
         cairo-xlib.h cairo-xlib-xrender.h cairo-ft.h ; do
  $FUGEN -rename="$rename" $a -- \
  `pkg-config --cflags cairo freetype2` >>cairo.interface
done
cat <<EOT >>cairo.interface
~}
undo word>sym
lazy off
EOT

fi

if [ ! -f zlib.interface ] ; then
cat <<EOT >zlib.interface
|
| zlib binding to HelFORTH
|
lazylink libz.so
context Zlib
{~ Zlib
EOT

$FUGEN zlib.h >>zlib.interface
cat <<EOT >>zlib.interface
~}
lazy off
EOT

fi

if [ ! -f bzlib.interface ] ; then
rename='$funa =~ s/BZ2_//;'
cat <<EOT >bzlib.interface
|
| bzlib binding to HelFORTH
|
| Requires: xstrings
lazylink libbz2.so
context Bzlib
::     " BZ2_" >pad >\$_ append \$_ ; is word>sym
{~ Bzlib
EOT

$FUGEN -rename="$rename" bzlib.h >>bzlib.interface
cat <<EOT >>bzlib.interface
~}
undo word>sym
lazy off
EOT

fi

if [ ! -f pcre.interface ] ; then
cat <<EOT >pcre.interface
|
| pcre binding to HelFORTH
|
lazylink libpcre.so
context Pcre
{~ Pcre
EOT

$FUGEN pcre.h >>pcre.interface
cat <<EOT >>pcre.interface
~}
lazy off
EOT

fi

if [ ! -f sqlite3.interface ] ; then
rename='$funa =~ s/sqlite3//;
$funa =~ s/_([a-z])/uc($1)/ge;'
renameback='$name = "sqlite3$name";
$name =~ s/([A-Z])/"_".lc($1)/ge;'
cat <<EOT >sqlite3.interface
|
| sqlite3 binding to HelFORTH
|
| Requires: xstrings
lazylink libsqlite3.so.0
::     " sqlite3" >pad over >r +
       swap 0 ?do
         over c@ dup 'a u<if dup 64 >if 32 or
           swap '_ over c! 1+ swap
         then then over c! 1+ swap 1+ swap
       loop nip r> tuck -
; is word>sym
context Sqlite3
{~ Sqlite3
EOT

$FUGEN -rename="$rename" sqlite3.h \
  | $BONG -rename="$renameback" /usr/lib/libsqlite3.so.0 >>sqlite3.interface
cat <<EOT >>sqlite3.interface
~}
undo word>sym
lazy off
EOT

fi

if [ ! -f gtk.interface ] ; then
cat <<EOT >gtk.interface
|
| gtk 2.0 binding to HelFORTH
|
context Gtk
{~ Gtk
EOT

for a in `(cd /usr/include/gtk-2.0/gtk ; ls)` ; do
  $FUGEN gtk/$a -- `pkg-config --cflags gtk+-2.0` \
  | $BONG /usr/lib/libgtk-x11-2.0.so >>gtk.interface
done
cat <<EOT >>gtk.interface
~}
EOT

fi
